﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection();
        cn.ConnectionString = WebConfigurationManager.ConnectionStrings["baglanti"].ToString();
        cn.Open();
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter("Select Birim_Adi from Birimler", cn);
        da.Fill(ds, "Table");
        drplistBirimler.DataSource = ds.Tables[0];
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            drplistBirimler.Items.Add(new ListItem(ds.Tables[0].Rows[i]["Birim_Adi"].ToString()));
        }
        cn.Close();
    }
    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        SqlConnection cn=new SqlConnection();
        cn.ConnectionString = WebConfigurationManager.ConnectionStrings["baglanti"].ToString();
        cn.Open();
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter("Select Oda_No from Kayitlar Where Oda_No Like '" + prefixText + "%'", cn);
        da.Fill(dt);
        string[] items = new string[dt.Rows.Count];
        int i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            items.SetValue(dr["Oda_No"].ToString(), i);
            i++;
        }
        cn.Close();
        return items;        
    }
    protected void btnGoruntule_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection();
        cn.ConnectionString = WebConfigurationManager.ConnectionStrings["baglanti"].ToString();
        cn.Open();
        SqlCommand cm = new SqlCommand("Select Birim_ID from Birimler Where Birim_Adi='" + drplistBirimler.SelectedValue + "'", cn);
        SqlDataReader dr = cm.ExecuteReader();
        string Birim_ID;
        if (dr.Read())
        {
            Birim_ID = dr["Birim_ID"].ToString();
        }
        else
            return;
        dr.Close();
        cm = new SqlCommand("Select Kayit_ID,ImagePath from Kayitlar Where Birim_ID='" + Birim_ID + "' And Kat_No='" + drplistKatlar.SelectedValue + "' And Oda_No='" + txtOdalar.Text + "'", cn);
        dr = cm.ExecuteReader();

        if (dr.Read())
        {
            Literal lt = new Literal();
            lt.Text = "<img src='image\\" + dr["ImagePath"].ToString() + "' class='fotoEtiket'/>";
            pnlImage.Controls.Add(lt);
        }
        else
            return;

        rpEtiketler.DataSource = db.DTGetir("Select * from Cihazlar K Where Kayit_ID=" + Convert.ToInt32(dr["Kayit_ID"]));
        rpEtiketler.DataBind();
        
        cn.Close();
    }
}